package org.darkforest.common.services.impl;

import org.darkforest.common.services.PBoothGoodsService;
import org.darkforest.dao.mapper.PBoothGoodsMapper;
import org.darkforest.dao.redis.PBoothGoodsRedisDao;
import org.darkforest.model.GoodsClass;
import org.darkforest.model.PBoothGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by pc on 2016/11/17.
 */
@Service
public class PBoothGoodsServiceImpl implements PBoothGoodsService {
    @Autowired
    private PBoothGoodsRedisDao pBoothGoodsRedisDao;
    @Autowired
    private PBoothGoodsMapper pBoothGoodsMapper;
    @Override
    public List<PBoothGoods> getRedisPBoothGoods(Integer recommondType,Integer gcId) {
        List<PBoothGoods> list = pBoothGoodsRedisDao.getPBoothGoodsListByKey("goods_index_" + recommondType + "_" + gcId);
        if(list==null || list.size()==0) {
            PBoothGoods pBoothGoods = new PBoothGoods();
            pBoothGoods.setPageSize(6);
            pBoothGoods.setStart(1);
            pBoothGoods.setBoothState((byte) 1);
            pBoothGoods.setGcId(gcId);
            pBoothGoods.setRecommondType(recommondType);
            list = pBoothGoodsMapper.selectRecommondGoodsByPage(pBoothGoods);
            pBoothGoodsRedisDao.addPBoothGoodsList("goods_index_" + recommondType + "_" + gcId, list);
        }
        return list;
    }
}
